using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVLSPEDV
    {
        public DataRow Convert2VLSPEDV(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVLSPEDV(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VLVMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VLVVERSART"] = " ".PadRight(3 ); 
         dwReturn["VLVSPED"] = " ".PadRight(3 ); 
         dwReturn["VLVTARIF"] = " ".PadRight(8 ); 
         dwReturn["VLVVERSI"] = " ".PadRight(2 ); 
         dwReturn["VLVGDATV"] = " ".PadRight(8 ); 
         dwReturn["VLVGDATB"] = " ".PadRight(8 ); 
         dwReturn["VLVMARGEF"] = " ".PadRight(3 ); 
         dwReturn["VLVSPERRIG"] = " ".PadRight(3 ); 
         dwReturn["VLVTPMBERKZ"] = " ".PadRight(1 ); 
         dwReturn["VLVTPMRUE"] = " ".PadRight(3 ); 
         dwReturn["VLVMARGER"] = " ".PadRight(3 ); 
         dwReturn["VLVGEWMAX"] = " ".PadRight(4 ); 
         dwReturn["VLVOKLMAX"] = " ".PadRight(2 ); 
         dwReturn["VLVOKLFST"] = " ".PadRight(2 ); 
         dwReturn["VLVNACHNA"] = " ".PadRight(3 ); 
         dwReturn["VLVNNAMIN"] = " ".PadRight(5 ); 
         dwReturn["VLVZOLLGB"] = " ".PadRight(7 ); 
         dwReturn["VLVZUSCHKZ"] = " ".PadRight(1 ); 
         dwReturn["VLVSABISKG"] = " ".PadRight(10 ); 
         dwReturn["VLVSAPROKG"] = " ".PadRight(10 ); 
         dwReturn["VLVSAZUWERT"] = " ".PadRight(14 ); 
         dwReturn["VLVSAZUMIN"] = " ".PadRight(14 ); 
         dwReturn["VLVSAWSL"] = " ".PadRight(6 ); 
         dwReturn["VLVSASTEUER"] = " ".PadRight(6 ); 
         dwReturn["VLVBEBISKG"] = " ".PadRight(20 ); 
         dwReturn["VLVBEPROKG"] = " ".PadRight(20 ); 
         dwReturn["VLVBEZUWERT"] = " ".PadRight(28 ); 
         dwReturn["VLVBEZUMIN"] = " ".PadRight(28 ); 
         dwReturn["VLVBEWSL"] = " ".PadRight(12 ); 
         dwReturn["VLVBESTEUER"] = " ".PadRight(12 ); 
         dwReturn["VLVBETEXT"] = " ".PadRight(40 ); 
         dwReturn["VLVFILLER"] = " ".PadRight(82 ); 
         dwReturn["VLVNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["VLVNEUDAT"] = " ".PadRight(6 ); 
         dwReturn["VLVAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["VLVAENDDAT"] = " ".PadRight(6 ); 
         dwReturn["VLVAENDZL"] = " ".PadRight(3 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVLSPEDV(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVLSPEDV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVLSPEDV(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVLSPEDV(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVLSPEDV(dwLocal, ITXDBVERSION);
            }
            UpdateVLSPEDV(dwLocal);
        }
        public void InsertVLSPEDV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VLSPEDV(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVLSPEDV(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VLSPEDV WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VLSPEDV  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VLSPEDV";
            Return = Result;
            return Return;
        }
        public void DeleteVLSPEDV(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VLSPEDV   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVLSPEDV(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VLSPEDV SET "
                    +"VLVMANDANT= :VLVMANDANT,"
                    +"VLVVERSART= :VLVVERSART,"
                    +"VLVSPED= :VLVSPED,"
                    +"VLVTARIF= :VLVTARIF,"
                    +"VLVVERSI= :VLVVERSI,"
                    +"VLVGDATV= :VLVGDATV,"
                    +"VLVGDATB= :VLVGDATB,"
                    +"VLVMARGEF= :VLVMARGEF,"
                    +"VLVSPERRIG= :VLVSPERRIG,"
                    +"VLVTPMBERKZ= :VLVTPMBERKZ,"
                    +"VLVTPMRUE= :VLVTPMRUE,"
                    +"VLVMARGER= :VLVMARGER,"
                    +"VLVGEWMAX= :VLVGEWMAX,"
                    +"VLVOKLMAX= :VLVOKLMAX,"
                    +"VLVOKLFST= :VLVOKLFST,"
                    +"VLVNACHNA= :VLVNACHNA,"
                    +"VLVNNAMIN= :VLVNNAMIN,"
                    +"VLVZOLLGB= :VLVZOLLGB,"
                    +"VLVZUSCHKZ= :VLVZUSCHKZ,"
                    +"VLVSABISKG= :VLVSABISKG,"
                    +"VLVSAPROKG= :VLVSAPROKG,"
                    +"VLVSAZUWERT= :VLVSAZUWERT,"
                    +"VLVSAZUMIN= :VLVSAZUMIN,"
                    +"VLVSAWSL= :VLVSAWSL,"
                    +"VLVSASTEUER= :VLVSASTEUER,"
                    +"VLVBEBISKG= :VLVBEBISKG,"
                    +"VLVBEPROKG= :VLVBEPROKG,"
                    +"VLVBEZUWERT= :VLVBEZUWERT,"
                    +"VLVBEZUMIN= :VLVBEZUMIN,"
                    +"VLVBEWSL= :VLVBEWSL,"
                    +"VLVBESTEUER= :VLVBESTEUER,"
                    +"VLVBETEXT= :VLVBETEXT,"
                    +"VLVFILLER= :VLVFILLER,"
                    +"VLVNEUBEN= :VLVNEUBEN,"
                    +"VLVNEUDAT= :VLVNEUDAT,"
                    +"VLVAENDBEN= :VLVAENDBEN,"
                    +"VLVAENDDAT= :VLVAENDDAT,"
                    +"VLVAENDZL= :VLVAENDZL,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VLVMANDANT", OracleType.NVarChar).Value = dwData["VLVMANDANT"].ToString(); 
          or1.Parameters.Add("VLVVERSART", OracleType.NVarChar).Value = dwData["VLVVERSART"].ToString(); 
          or1.Parameters.Add("VLVSPED", OracleType.NVarChar).Value = dwData["VLVSPED"].ToString(); 
          or1.Parameters.Add("VLVTARIF", OracleType.NVarChar).Value = dwData["VLVTARIF"].ToString(); 
          or1.Parameters.Add("VLVVERSI", OracleType.NVarChar).Value = dwData["VLVVERSI"].ToString(); 
          or1.Parameters.Add("VLVGDATV", OracleType.NVarChar).Value = dwData["VLVGDATV"].ToString(); 
          or1.Parameters.Add("VLVGDATB", OracleType.NVarChar).Value = dwData["VLVGDATB"].ToString(); 
          or1.Parameters.Add("VLVMARGEF", OracleType.NVarChar).Value = dwData["VLVMARGEF"].ToString(); 
          or1.Parameters.Add("VLVSPERRIG", OracleType.NVarChar).Value = dwData["VLVSPERRIG"].ToString(); 
          or1.Parameters.Add("VLVTPMBERKZ", OracleType.NVarChar).Value = dwData["VLVTPMBERKZ"].ToString(); 
          or1.Parameters.Add("VLVTPMRUE", OracleType.NVarChar).Value = dwData["VLVTPMRUE"].ToString(); 
          or1.Parameters.Add("VLVMARGER", OracleType.NVarChar).Value = dwData["VLVMARGER"].ToString(); 
          or1.Parameters.Add("VLVGEWMAX", OracleType.NVarChar).Value = dwData["VLVGEWMAX"].ToString(); 
          or1.Parameters.Add("VLVOKLMAX", OracleType.NVarChar).Value = dwData["VLVOKLMAX"].ToString(); 
          or1.Parameters.Add("VLVOKLFST", OracleType.NVarChar).Value = dwData["VLVOKLFST"].ToString(); 
          or1.Parameters.Add("VLVNACHNA", OracleType.NVarChar).Value = dwData["VLVNACHNA"].ToString(); 
          or1.Parameters.Add("VLVNNAMIN", OracleType.NVarChar).Value = dwData["VLVNNAMIN"].ToString(); 
          or1.Parameters.Add("VLVZOLLGB", OracleType.NVarChar).Value = dwData["VLVZOLLGB"].ToString(); 
          or1.Parameters.Add("VLVZUSCHKZ", OracleType.NVarChar).Value = dwData["VLVZUSCHKZ"].ToString(); 
          or1.Parameters.Add("VLVSABISKG", OracleType.NVarChar).Value = dwData["VLVSABISKG"].ToString(); 
          or1.Parameters.Add("VLVSAPROKG", OracleType.NVarChar).Value = dwData["VLVSAPROKG"].ToString(); 
          or1.Parameters.Add("VLVSAZUWERT", OracleType.NVarChar).Value = dwData["VLVSAZUWERT"].ToString(); 
          or1.Parameters.Add("VLVSAZUMIN", OracleType.NVarChar).Value = dwData["VLVSAZUMIN"].ToString(); 
          or1.Parameters.Add("VLVSAWSL", OracleType.NVarChar).Value = dwData["VLVSAWSL"].ToString(); 
          or1.Parameters.Add("VLVSASTEUER", OracleType.NVarChar).Value = dwData["VLVSASTEUER"].ToString(); 
          or1.Parameters.Add("VLVBEBISKG", OracleType.NVarChar).Value = dwData["VLVBEBISKG"].ToString(); 
          or1.Parameters.Add("VLVBEPROKG", OracleType.NVarChar).Value = dwData["VLVBEPROKG"].ToString(); 
          or1.Parameters.Add("VLVBEZUWERT", OracleType.NVarChar).Value = dwData["VLVBEZUWERT"].ToString(); 
          or1.Parameters.Add("VLVBEZUMIN", OracleType.NVarChar).Value = dwData["VLVBEZUMIN"].ToString(); 
          or1.Parameters.Add("VLVBEWSL", OracleType.NVarChar).Value = dwData["VLVBEWSL"].ToString(); 
          or1.Parameters.Add("VLVBESTEUER", OracleType.NVarChar).Value = dwData["VLVBESTEUER"].ToString(); 
          or1.Parameters.Add("VLVBETEXT", OracleType.NVarChar).Value = dwData["VLVBETEXT"].ToString(); 
          or1.Parameters.Add("VLVFILLER", OracleType.NVarChar).Value = dwData["VLVFILLER"].ToString(); 
          or1.Parameters.Add("VLVNEUBEN", OracleType.NVarChar).Value = dwData["VLVNEUBEN"].ToString(); 
          or1.Parameters.Add("VLVNEUDAT", OracleType.NVarChar).Value = dwData["VLVNEUDAT"].ToString(); 
          or1.Parameters.Add("VLVAENDBEN", OracleType.NVarChar).Value = dwData["VLVAENDBEN"].ToString(); 
          or1.Parameters.Add("VLVAENDDAT", OracleType.NVarChar).Value = dwData["VLVAENDDAT"].ToString(); 
          or1.Parameters.Add("VLVAENDZL", OracleType.NVarChar).Value = dwData["VLVAENDZL"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
